package chapter01;

public class Bag {
    public static int process(int[] weights,int[] values,int i,int alreadyweight,int bag){
        if(alreadyweight>bag){
            return -values[i-1];
        }
        if(i==weights.length){
            return 0;
        }
        return Math.max(process(weights,values,i+1,alreadyweight,bag),values[i]+process(weights,values,i+1,alreadyweight+weights[i],bag));
    }

    public static void main(String[] args) {
        int[] weights={2,3,5,7};
        int[] values={3,4,5,8};
        System.out.println(process(weights,values,0,0,12));
    }
}
